package cc.taofoo.JUC;

public class WaitNotifyTest {
    public static void main(String[] args) {
        Thread t1 = new Thread(new TestRunnable(1));
        Thread t2 = new Thread(new TestRunnable(2));
        t1.start();t2.start();
    }
}

class TestRunnable implements Runnable {
    static Object object = new Object();
    int id;

    public TestRunnable(int id) {
        this.id = id;
    }

    @Override
    public void run() {
        try {

            if (id == 1)
                synchronized (object) {
                    object.wait();
                }
            else {
                synchronized (object){
                    object.notify();
                }
            }

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

